<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/18
  Time: 23:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String id=request.getParameter("id");
  request.setAttribute("id",id);
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="author" content="order by dede58.com"/><title>后台管理系统</title>
    <link rel="stylesheet" href="../../static/css/style.css">
    <link rel="stylesheet" href="../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../static/js/min.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body class="modal white">
<script type="text/javascript" src="../../static/js/main.js"></script>
<link rel="stylesheet" href="../../static/css/style2.css">
<div id="content" class="white" style="margin-left:242px">
    <div class="bloc">
        <div class="title" style="margin-top: 40px">更新员工</div>
        <div class="content" >
            <form  id="modify">
                <div class="input">
                    <input type="hidden" id="uid" name="id">
            <label>所属部门:</label>
                <select name="department" id="selectID">
                <option value="1001">工程部</option>
                <option value="1002">市场部</option>
                <option value="1003">开发部</option>
                <option value="1004">行政财务部</option>
                <option value="1005">客户服务部</option>
            </select></div>
                <div class="input">
                    <label for="login_name">登录名称:</label>
                    <input type="text" id="login_name" name="login_name">
                </div>
            <div class="input">
                <label for="real_name">真实姓名:</label>
                <input type="text" id="real_name" name="real_name">
            </div>
              <div class="input">
                  <label for="password">用户密码:</label>
                  <input type="password" id="password" name="password">
              </div>
            <div class="input">
                <label for="Email">Email:</label>
                <input type="text" id="Email" name="Email">
            </div>
            <div class="input">
                <label>联系电话:</label>
                <input type="text" id="tel" name="tel">
            </div>
           <div class="input">
               <label>用户性别:</label>
               <input type="radio"  name="sex" value="1" checked class="input radio">男&nbsp;&nbsp;
               <input type="radio"  name="sex" value="2" class="input radio">女
               </label>
           </div>
                <div class="input">
                    <label>员工职位:</label>
                    <select name="role">
                        <option value="1">自动化工程师</option>
                        <option value="2">程序员</option>
                        <option value="3">部门经理</option>
                        <option value="4">实施工程师</option>
                        <option value="5">运维工程师</option>
                    </select>
                </div>
              <div class="input">
                  <label for="address">联系地址:</label>
                  <input type="text" id="address" name="address">
              </div>
            <div class="input">
                <label>员工状态:</label>
                <select name="status">
                    <option value="1">在职</option>
                    <option value="2">离职</option>
                    <option value="3">退休</option>
                </select>
            </div>
                <div class="input">
                    <label>删除标志:</label>
                        <select name="delflag">
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                </div>
            <br/>
                <input class="btn btn-danger" type="reset" id="reset" value="重置">
        </form>
            <input class="btn btn-success" type="submit" id="submit"
                   value="提交" style="margin-left: 50px" onclick="okConmit()">
        </div>
    </div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">
    $.ajax({
        url:"<%=request.getContextPath()%>/userServlet",
        data:"Id=${id}&opr=detailUser",
        dataType:"json",
        type:"POST",
        success:function (result) {
            console.log(result);
            var $option=$("#selectID option");
            for (var i=0;i<$option.length;i++){
                if ($option.val()===result.dept_id){
                    $option.attr("selected","selected");
                }
            }
            
            $("#uid").val(${id});
            $("#login_name").val(result.login_name);
            $("#real_name").val(result.real_name);
            $("#Email").val(result.email);
            $("#tel").val(result.tel);
            $("#address").val(result.address);


        }
    })

    function okConmit() {
        var queryStr=$("form#modify").serialize();
        $.ajax({
            url:"<%=request.getContextPath()%>/userServlet",
            data:"opr=updateUser&"+queryStr,
            dataType:"text",
            type:"GET",
            success:function (result) {
                console.log(result);
                if (result=="true"){
                    alert("更新员工成功！");
                    window.location.href="employeemanage.jsp";
                    
                }else {
                    alert("更新员工失败！");
                }
            },
            error:function () {
                alert("111111111111");
            }
        })
    }
</script>
</body>
</html>
